package org.pr.ddddesigner.application;

import org.pr.ddddesigner.application.transfer.UserInfoDtoToEntity;
import org.pr.ddddesigner.domain.aggregation.model.User;
import org.pr.ddddesigner.domain.service.UserDomainService;
import org.pr.ddddesigner.interfaces.dto.CreateUser;
import org.pr.ddddesigner.interfaces.dto.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

/**
 * @description:
 * @projectName:DDD-Designer
 * @see:org.pr.ddddesigner.application
 * @author:LXC
 * @createTime:2024/4/19 13:49
 * @version:1.0
 */
@Service
public class UserApplicationService {

    @Autowired
    private UserDomainService service;

    @Autowired(required = false)
    private UserInfoDtoToEntity userInfoDtoToEntity;

    public Mono<UserInfo> createUser(CreateUser createUser){
        User user = User.getFactory().make();
        user.setUserId(createUser.getUserId());
        user.setUserName(createUser.getUserName());
        user.setUserAge(createUser.getUserAge());
        return service.saveUser(user).map(userInfoDtoToEntity::toDto);
    }
}
